package com.lsx.action;

import javax.annotation.Resource;

import org.springframework.ui.Model;  

import javax.servlet.http.HttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.lsx.pojo.User;
import com.lsx.service.impl.UserServiceImpl;

@Controller  
@RequestMapping("/user")  
public class UserController {
		@Resource  
	    private UserServiceImpl userService;  
	      
	    @RequestMapping("/showUser")  
	    public String toIndex(HttpServletRequest request,Model model){  
	        int userId = Integer.parseInt(request.getParameter("id"));  
	        User user = this.userService.findUserById(userId);
	        model.addAttribute("user", user);  
	        return "showUser";  
	    }  
	    
	    @RequestMapping("/addUser")  
	    public String addUser(Model model){  
	        User user = new User();
	        Integer num=0;
	        for (int i = 0; i < 100; i++) {
				if(i<=25){
					user.setUsername("pos"+i);
					user.setPassword("pwd"+i);
				}else if(i<=50){
					user.setUsername("join"+i);
					user.setPassword("pwd"+i);
				}else if(i<=75){
					user.setUsername("dels"+i);
					user.setPassword("pwd"+i);
				}else{
					user.setUsername("oyo"+i);
					user.setPassword("pwd"+i);
				}
				num=this.userService.addUser(user);
			}
	        model.addAttribute("num",num);  
	        return "showUser";  
	    }

}
